/** 教程链接：
 * https://dart.cn/language/#enums
 */
// Dart 枚举与增强型枚举示例

// 枚举类型：表示行星的类型
enum PlanetType {
  terrestrial, // 类地行星
  gas,         // 气态巨行星
  ice          // 冰巨行星
}

// 增强型枚举：表示太阳系中行星及其属性
enum Planet {
  // 定义枚举实例，每个实例都带有额外的信息
  mercury(planetType: PlanetType.terrestrial, moons: 0, hasRings: false),
  venus(planetType: PlanetType.terrestrial, moons: 0, hasRings: false),
  earth(planetType: PlanetType.terrestrial, moons: 1, hasRings: false),
  mars(planetType: PlanetType.terrestrial, moons: 2, hasRings: false),
  jupiter(planetType: PlanetType.gas, moons: 79, hasRings: true),
  saturn(planetType: PlanetType.gas, moons: 83, hasRings: true),
  uranus(planetType: PlanetType.ice, moons: 27, hasRings: true),
  neptune(planetType: PlanetType.ice, moons: 14, hasRings: true);

  // 常量构造函数，定义字段并接收参数
  const Planet({
    required this.planetType,
    required this.moons,
    required this.hasRings,
  });

  // 所有字段必须是 final（不可变）
  final PlanetType planetType; // 行星类型
  final int moons;             // 卫星数量
  final bool hasRings;         // 是否有环

  // 增强型枚举支持 getter 和方法
  bool get isGiant =>
      planetType == PlanetType.gas || planetType == PlanetType.ice;
}

void main() {
  // 示例：选定你的星球
  final yourPlanet = Planet.earth;

  print('Your planet is ${yourPlanet.name}.');
  print('Type: ${yourPlanet.planetType}');
  print('Moons: ${yourPlanet.moons}');
  print('Has rings? ${yourPlanet.hasRings}');
  print('Is giant? ${yourPlanet.isGiant ? "Yes" : "No"}');

  // 也可以遍历所有行星
  print('\nAll planets:');
  for (final planet in Planet.values) {
    print('- ${planet.name}: ${planet.planetType}, '
        '${planet.moons} moon(s), rings: ${planet.hasRings}');
  }
}
